home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / assert / assert.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-19  |  2.7 KB  |  96 lines

  1. /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. /*
  20.  *    ANSI Standard: 4.2 DIAGNOSTICS    <assert.h>
  21.  */
  22.  
  23. #ifdef    _ASSERT_H
  24.  
  25. #undef    _ASSERT_H
  26. #undef    assert
  27.  
  28. #endif /* assert.h    */
  29.  
  30. #define    _ASSERT_H    1
  31. #include <features.h>
  32.  
  33. /* void assert (int expression);
  34.  
  35.    If NDEBUG is defined, do nothing.
  36.    If not, and EXPRESSION is zero, print an error message and abort.  */
  37.  
  38. #ifdef    NDEBUG
  39.  
  40. #define    assert(expr)        ((void) 0)
  41.  
  42. /* void assert_perror (int errnum);
  43.  
  44.    If NDEBUG is defined, do nothing.  If not, and ERRNUM is not zero, print an
  45.    error message with the error text for ERRNUM and abort.
  46.    (This is a GNU extension.) */
  47.  
  48. #ifdef    __USE_GNU
  49. #define    assert_perror(errnum)    ((void) 0)
  50. #endif
  51.  
  52. #else /* Not NDEBUG.  */
  53.  
  54. #include <sys/cdefs.h>
  55.  
  56. __BEGIN_DECLS
  57.  
  58. /* This prints an "Assertion failed" message and aborts.  */
  59. extern __NORETURN int __assert_fail __P ((__const char *__assertion,
  60.                       __const char *__file,
  61.                       unsigned int __line,
  62.                       __const char *__function));
  63.  
  64. /* Likewise, but prints the error text for ERRNUM.  */
  65. extern __NORETURN int __assert_perror_fail __P ((int __errnum,
  66.                          __const char *__file,
  67.                          unsigned int __line,
  68.                          __const char *__function));
  69.  
  70. __END_DECLS
  71.  
  72. #define    assert(expr)                                   \
  73.   ((void) ((expr) || __assert_fail (__STRING(expr),                  \
  74.                     __FILE__, __LINE__, __ASSERT_FUNCTION)))
  75.  
  76. #ifdef    __USE_GNU
  77. #define assert_perror(errnum)                              \
  78.   ((void) ((errnum) && __assert_perror_fail ((errnum),                  \
  79.                          __FILE__, __LINE__,          \
  80.                          __ASSERT_FUNCTION)))
  81. #endif
  82.  
  83. /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
  84.    which contains the name of the function currently being defined.
  85.    This is broken in G++ before version 2.6.  */
  86. #if (!defined (__GNUC__) || __GNUC__ < 2 || \
  87.      __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4))
  88. #define __ASSERT_FUNCTION    ((__const char *) 0)
  89. #else
  90. #define __ASSERT_FUNCTION    __PRETTY_FUNCTION__
  91. #endif
  92.  
  93.  
  94. #endif /* NDEBUG.  */
  95.  
  96.